package com.hndct.util;

import java.util.Random;

public class OrderUtil {
	
	/**
	 * 生成订单号
	 * @param userId
	 * @return
	 */
	public static String getOrderNo(int userId){
		StringBuilder sb = new StringBuilder();
		//前三位，1000以内随机数
		sb.append(RandomUtil.getRandomNum(10));
		sb.append(RandomUtil.getRandomNum(10));
		sb.append(RandomUtil.getRandomNum(10));
		
		//拼接当前13位时间戳
		sb.append(System.currentTimeMillis());
		
		//拼接userId
		sb.append(userId);
		
		return sb.toString();
	}

	/**
	 * 功能描述:
	 * @param :
	 * @Return: java.lang.String
	 * @Auther: YuZhenDong
	 * @Date: 2019/4/12
	 * @Discription: 订单号
	 */
	public static String getOrderCode(){
		return "O"+System.currentTimeMillis()+getFourRandom();
	}

	public static String getFourRandom(){
		Random random = new Random();
		String fourRandom = String.valueOf(random.nextInt(10000));
		int randLength = fourRandom.length();
		if(randLength<4){
			for(int i=1; i<=4-randLength; i++)
				fourRandom = String.valueOf(fourRandom);
		}
		return fourRandom;
	}

	/*public static void main(String[] args) {
		String code = "0x5aaa6ee46114c3c14fb0aa093970447dfdb34853";
		System.out.println(getOrderCode());
		System.out.println(code.length());
	}*/
}
